package com.example.park_2306

import android.content.Intent
import android.os.Bundle
import android.view.KeyEvent
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.navigation.findNavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.SPUtils
import com.example.base.mvi.BaseViewActivity
import com.example.park_2306.databinding.ActivityMainBinding
import com.google.android.material.bottomnavigation.BottomNavigationView
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/MainActivity")
class MainActivity : BaseViewActivity<ActivityMainBinding>() {
    //对外暴露一个底部导航
    lateinit var bottom:BottomNavigationView
    override fun getLayout(): Int  = R.layout.activity_main

    override fun initView() {
        val hostFragment =
            supportFragmentManager.findFragmentById(R.id.fragmentContainerView) as NavHostFragment
        val navController = hostFragment.navController
        binding.bottom.setupWithNavController(navController)

        navController.navigate(R.id.serviceFragment)

        //显示消息小圆点
        bottom = binding.bottom
        bottom.getOrCreateBadge(R.id.shopFragment).number = 10
        //点击对应菜单 ，小圆点消失
        binding.bottom.setOnItemSelectedListener {
            when(it.itemId){
                R.id.shopFragment->{
                    binding.bottom.removeBadge(R.id.shopFragment)
                }
            }
            navController.navigate(it.itemId)
            return@setOnItemSelectedListener true
        }

      /*  binding.bottom.menu.findItem(R.id.shopFragment).setOnMenuItemClickListener {
            binding.bottom.removeBadge(R.id.shopFragment)
            return@setOnMenuItemClickListener false
        }*/
    }
    //点击返回键时记录当前时间
    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        if(keyCode==KeyEvent.KEYCODE_BACK){
            SPUtils.getInstance().put("time",System.currentTimeMillis())
        }
        return super.onKeyDown(keyCode, event)
    }


}